package com.cal.utms.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.*;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.cal.utms.logAudit.AuditLogInt;
import com.cal.utms.util.ValueConvert;

/**
 * The persistent class for the customer database table.
 * 
 */
@Entity
@Table(name = "customer")
@NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c")
public class Customer implements Serializable, AuditLogInt {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	@Column(name = "ACCOUNT_TYPE")
	private String accountType;

	@Column(name = "CODE")
	private String code;

	@Column(name = "CORRESPONDING_ADDRESS")
	private String correspondingAddress;

	@Column(name = "CUSTOMER_TYPE")
	private String customerType;

	@Column(name = "DENOTED_BY_INITIALS")
	private String denotedByInitials;

	@Column(name = "FAX")
	private String fax;

	@Column(name = "FM_ID")
	private Integer fmId;

	@Column(name = "GENERAL_ADDRESS")
	private String generalAddress;

	@Column(name = "INITIALS")
	private String initials;

	@Column(name = "NIC_PASSPORT")
	private String nicPassport;

	@Column(name = "PHONE")
	private String phone;

	@Column(name = "MOBILENO")
	private String mobileNo;

	@Column(name = "RESIDENTIAL")
	private String residential;

	@Column(name = "SURNAME")
	private String surname;

	@Column(name = "TITLE")
	private String title;

	@Column(name = "CORRES_EMAIL")
	private byte corresEmail;

	@Column(name = "CORRES_FAX")
	private byte corresFax;

	@Column(name = "CORRES_INST")
	private String corresInst;

	@Column(name = "CORRES_POST")
	private byte corresPost;

	@Column(name = "BANK_INSTRUCTION")
	private String bankInstrution;

	@OneToMany(mappedBy = "customer", cascade = { CascadeType.ALL })
	@Fetch(value = FetchMode.SUBSELECT)
	private List<CustomerContactPerson> customerContactPersons;

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "customer", cascade = { CascadeType.ALL })
	@Fetch(value = FetchMode.SUBSELECT)
	private List<CustomerJointAppicant> customerJointAppicants;

	@OneToMany(mappedBy = "customer", cascade = { CascadeType.ALL })
	@Fetch(value = FetchMode.SUBSELECT)
	private List<CustomerEmail> customerEmails;

	@OneToMany(mappedBy = "customer", cascade = { CascadeType.ALL })
	@Fetch(value = FetchMode.SUBSELECT)
	private List<CustomerBankAccount> customerBankAccounts;

	public Customer() {
	}

	public Customer(int id) {

	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getAccountType() {
		return this.accountType;
	}

	public void setAccountType(String accountType) {
		this.accountType = accountType;
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getCorrespondingAddress() {
		return this.correspondingAddress;
	}

	public void setCorrespondingAddress(String correspondingAddress) {
		this.correspondingAddress = correspondingAddress;
	}

	public String getCustomerType() {
		return this.customerType;
	}

	public void setCustomerType(String customerType) {
		this.customerType = customerType;
	}

	public String getDenotedByInitials() {
		return this.denotedByInitials;
	}

	public void setDenotedByInitials(String denotedByInitials) {
		this.denotedByInitials = denotedByInitials;
	}

	public String getFax() {
		return this.fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public Integer getFmId() {
		return this.fmId;
	}

	public void setFmId(Integer fmId) {
		this.fmId = fmId;
	}

	public String getGeneralAddress() {
		return this.generalAddress;
	}

	public void setGeneralAddress(String generalAddress) {
		this.generalAddress = generalAddress;
	}

	public String getInitials() {
		return this.initials;
	}

	public void setInitials(String initials) {
		this.initials = initials;
	}

	public String getNicPassport() {
		return this.nicPassport;
	}

	public void setNicPassport(String nicPassport) {
		this.nicPassport = nicPassport;
	}

	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getMobileNo() {
		return mobileNo;
	}

	public void setMobileNo(String mobileNo) {
		this.mobileNo = mobileNo;
	}

	public String getResidential() {
		return this.residential;
	}

	public void setResidential(String residential) {
		this.residential = residential;
	}

	public String getSurname() {
		return this.surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public byte getCorresEmail() {
		return corresEmail;
	}

	public void setCorresEmail(byte corresEmail) {
		this.corresEmail = corresEmail;
	}

	public byte getCorresFax() {
		return corresFax;
	}

	public void setCorresFax(byte corresFax) {
		this.corresFax = corresFax;
	}

	public String getCorresInst() {
		return corresInst;
	}

	public void setCorresInst(String corresInst) {
		this.corresInst = corresInst;
	}

	public byte getCorresPost() {
		return corresPost;
	}

	public void setCorresPost(byte corresPost) {
		this.corresPost = corresPost;
	}

	public String getBankInstrution() {
		return bankInstrution;
	}

	public void setBankInstrution(String bankInstrution) {
		this.bankInstrution = bankInstrution;
	}

	public List<CustomerContactPerson> getCustomerContactPersons() {
		return this.customerContactPersons;
	}

	public void setCustomerContactPersons(List<CustomerContactPerson> customerContactPersons) {
		this.customerContactPersons = customerContactPersons;
	}

	public CustomerContactPerson addCustomerContactPerson(CustomerContactPerson customerContactPerson) {
		getCustomerContactPersons().add(customerContactPerson);
		customerContactPerson.setCustomer(this);

		return customerContactPerson;
	}

	public CustomerContactPerson removeCustomerContactPerson(CustomerContactPerson customerContactPerson) {
		getCustomerContactPersons().remove(customerContactPerson);
		customerContactPerson.setCustomer(null);

		return customerContactPerson;
	}

	public List<CustomerJointAppicant> getCustomerJointAppicants() {
		return this.customerJointAppicants;
	}

	public void setCustomerJointAppicants(List<CustomerJointAppicant> customerJointAppicants) {
		this.customerJointAppicants = customerJointAppicants;
	}

	public CustomerJointAppicant addCustomerJointAppicant(CustomerJointAppicant customerJointAppicant) {
		getCustomerJointAppicants().add(customerJointAppicant);
		customerJointAppicant.setCustomer(this);

		return customerJointAppicant;
	}

	public CustomerJointAppicant removeCustomerJointAppicant(CustomerJointAppicant customerJointAppicant) {
		getCustomerJointAppicants().remove(customerJointAppicant);
		customerJointAppicant.setCustomer(null);

		return customerJointAppicant;
	}

	public List<CustomerEmail> getCustomerEmails() {
		return customerEmails;
	}

	public void setCustomerEmails(List<CustomerEmail> customerEmails) {
		this.customerEmails = customerEmails;
	}

	public CustomerEmail addCustomerEmail(CustomerEmail customerEmail) {
		getCustomerEmails().add(customerEmail);
		customerEmail.setCustomer(this);

		return customerEmail;
	}

	public CustomerEmail removeCustomerEmail(CustomerEmail customerEmail) {
		getCustomerEmails().remove(customerEmail);
		customerEmail.setCustomer(null);

		return customerEmail;
	}

	public List<CustomerBankAccount> getCustomerBankAccounts() {
		return customerBankAccounts;
	}

	public void setCustomerBankAccounts(List<CustomerBankAccount> customerBankAccounts) {
		this.customerBankAccounts = customerBankAccounts;
	}

	public CustomerBankAccount addBankAccount(CustomerBankAccount bankAccount) {
		getCustomerBankAccounts().add(bankAccount);
		bankAccount.setCustomer(this);

		return bankAccount;
	}

	public CustomerBankAccount removeBankAccount(CustomerBankAccount bankAccount) {
		getCustomerBankAccounts().remove(bankAccount);
		bankAccount.setCustomer(null);

		return bankAccount;
	}

	@Transient
	@Override
	public Long getLogId() {
		return ValueConvert.toLong(this.id);
	}

	@Transient
	@Override
	public String getLogDeatil() {
		StringBuilder sb = new StringBuilder();
		sb.append("Customer Id : ").append(id).append("Customer code : ").append(this.code);

		return sb.toString();
	}
}